package com.du.spring5.bean;

import org.springframework.beans.factory.FactoryBean;

/**
 * @author : DuJiabao
 * @Date : 2021/2/3 15:46
 * @Project : spring
 * @File : null.java
 * @Desc : 工厂bean，用来生产bean
 */
public class UserFactoryBean implements FactoryBean<User> {
    private static int count = 0;

    @Override
    public User getObject() throws Exception {
        User user = new User();
        user.setName("name " + count);  // 可以通过外部文件的方式指定
        user.setId(count++);
        return user;
    }

    @Override
    public Class<User> getObjectType() {
        return User.class;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }
}
